refactor(gt-i18n): registration interface#18
Merged
ErnestM1234 merged 5 commits intomainfrom Mar 8, 2026
Merged
Conversation
|
@greptileai review |
1 similar comment
|
@greptileai review |
Contributor
Author
idk if greptile is real bro |
packages/gt-i18n/src/gt_i18n/translation_functions/_extract_variables.py
Outdated
Show resolved
Hide resolved
Contributor
Author
|
@greptileai plz review |
packages/gt-i18n/src/gt_i18n/translation_functions/_interpolate.py
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

for string registration, move arguments from a dictionary to kwargs and convert sugar syntax to underscores
Greptile Summary
This PR refactors the
gt-i18nstring registration interface by renaming all$-prefixed GT reserved keys to underscore-prefixed equivalents ($context→_context,$id→_id,$max_chars→_max_chars,$_source→__source,$_hash→__hash,$_fallback→__fallback), making kwargs valid Python identifiers. It also addresses previous review feedback by replacing the brittle prefix-based variable filtering with an explicit_GT_RESERVED_KEYSblocklist, and by extracting duplicated test helper code into a sharedhelpers.pymodule.Key changes:
_extract_variables.py: New_GT_RESERVED_KEYSfrozenset replacesstartswith("$")filter — user variables with_prefixes are no longer silently dropped_msg.py,_t.py,_interpolate.py,_is_encoded.py: All internal key lookups updated to new naming conventiontests/helpers.py+tests/conftest.py: Shared test utilities extracted (resolving the duplicated-helper concern from the prior review)_interpolate.py: step 1 still describes the old prefix-filtering behavior rather than the new explicit blocklistConfidence Score: 5/5
$-prefixed keys are replaced uniformly across production code and tests. The blocklist-based filtering inextract_variablesis correct and complete (_context,_id,_max_chars,__hash,__source,__fallbackall included). A new test explicitly verifies user_-prefixed vars are preserved. The only finding is a minor stale docstring on a single line in_interpolate.py._interpolate.py.Important Files Changed
_GT_RESERVED_KEYSblocklist, correctly addressing the previous review concern about user variables starting with_being silently dropped.$_fallback/$max_charsto__fallback/_max_chars. Minor docstring inconsistency on line 28 still says "filter out_-prefixed keys" but the actual logic now uses an explicit blocklist.$-prefixed keys ($_hash,$context,$id,$max_chars) correctly renamed to their_/__equivalents. Encoding path and hash logic remain intact.JS_TO_PY_KEY_MAP,convert_keys, andconvert_encoded_string, directly resolving the duplicated-helper concern from the previous review.test_user_underscore_prefixed_keys_preserved) correctly validates that user variables with a_prefix are no longer silently dropped.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["t(message, **kwargs)\n_context, _id, _max_chars"] --> B["hash_message()\nuses _context, _id, _max_chars"] A --> C{"translation found?"} C -->|yes| D["interpolate_message(translated,\n{**kwargs, __fallback: message})"] C -->|no| E["interpolate_message(message, kwargs)"] D --> F["extract_variables(options)\nblocks _GT_RESERVED_KEYS"] E --> F F --> G["user vars only\n(e.g. name, count, _custom_var ✓)"] F --> H["GT reserved keys removed\n_context, _id, _max_chars\n__hash, __source, __fallback"] D --> I{"format error?"} I -->|"__fallback present"| J["retry with source msg\n(__fallback=None)"] I -->|no fallback| K["return raw + _max_chars cutoff"] J --> L["interpolated result"] G --> LLast reviewed commit: 1da7587